package images;

import java.util.HashMap;
import java.util.Map;

import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Animation;
import com.uqbar.vainilla.appearances.Sprite;
import components.appearance.DestroyAnimation;
import components.appearance.LinealAnimation;

public class Images {

	public static GameImagesMap images = new GameImagesMap();
		
	public static Map<String, Sprite[]> animations;

	public Images() {
		animations = new HashMap<String, Sprite[]>();
		
		images.addSprite("wormStill-1", Sprite.fromImage("/images/worm/wstill-1.PNG"));
		images.addSprite("wormStill1", Sprite.fromImage("/images/worm/wstill1.PNG"));
		
		images.addSprite("sight", Sprite.fromImage("/images/worm/sight.PNG"));

		images.addSprite("indicador", Sprite.fromImage("/images/presentation/indicador.PNG"));
		
		images.addSprite("powerBar1",Sprite.fromImage("/images/worm/barraDePotencia/barra2.PNG").scale(0.3, 0.9));
		images.addSprite("powerBar2",Sprite.fromImage("/images/worm/barraDePotencia/barra2.PNG").scale(0.3, 0.9));
		images.addSprite("powerBar3",Sprite.fromImage("/images/worm/barraDePotencia/barra3.PNG").scale(0.3, 0.9));
		images.addSprite("powerBar4",Sprite.fromImage("/images/worm/barraDePotencia/barra4.PNG").scale(0.3, 0.9));
		images.addSprite("powerBar5",Sprite.fromImage("/images/worm/barraDePotencia/barra5.PNG").scale(0.3, 0.9));
		images.addSprite("powerBar6",Sprite.fromImage("/images/worm/barraDePotencia/barra6.PNG").scale(0.3, 0.9));
		images.addSprite("powerBar7",Sprite.fromImage("/images/worm/barraDePotencia/barra7.PNG").scale(0.3, 0.9));
		images.addSprite("powerBar8",Sprite.fromImage("/images/worm/barraDePotencia/barra8.PNG").scale(0.3, 0.9));
		images.addSprite("powerBar9",Sprite.fromImage("/images/worm/barraDePotencia/barra9.PNG").scale(0.3, 0.9));
		images.addSprite("powerBar9",Sprite.fromImage("/images/worm/barraDePotencia/barra10.PNG").scale(0.3, 0.9));
		
		images.addSprite("bazooka-p", Sprite.fromImage("/weapon/bazooka_proyectil.PNG").scaleTo(25, 25));
		images.addSprite("dynamite-p", Sprite.fromImage("/weapon/dynamite_proyectil.PNG").scaleTo(10, 30));
		images.addSprite("gun-p", Sprite.fromImage("/weapon/missile_proyectil.PNG").scaleTo(10, 20));
		
		addAnimationExplode();
		addAnimationWalk();
		addAnimationBazooka();
		addAnimationWormFalling();
		addAnimationWormJumping();
		addAnimationGun();
		addAnimationDinamite();
	}

	
	public static void rotarSprites(String key,double angle){
		for(Sprite s:animations.get(key)){
			s.rotate(angle);
		}
	}
	
	private void addAnimationExplode() {
		Sprite[] sps = {
		
		Sprite.fromImage("/animations/explosion/exp01.png"),
		Sprite.fromImage("/animations/explosion/exp02.png"),
		Sprite.fromImage("/animations/explosion/exp03.png"),
		Sprite.fromImage("/animations/explosion/exp04.png"),
		Sprite.fromImage("/animations/explosion/exp05.png"),
		Sprite.fromImage("/animations/explosion/exp06.png"),
		Sprite.fromImage("/animations/explosion/exp07.png"),
		Sprite.fromImage("/animations/explosion/exp08.png"),
		Sprite.fromImage("/animations/explosion/exp09.png"),
		Sprite.fromImage("/animations/explosion/exp10.png"),
		Sprite.fromImage("/animations/explosion/exp11.png"),
		Sprite.fromImage("/animations/explosion/exp12.png"),
		Sprite.fromImage("/animations/explosion/exp13.png"),
		Sprite.fromImage("/animations/explosion/exp14.png"),
		Sprite.fromImage("/animations/explosion/exp15.png"),
		 };
		
		animations.put("explosion", sps);
	}

	private void addAnimationWalk(){
		Sprite[] walkingLeftSprites = new Sprite[15];
		walkingLeftSprites[0]=Sprite.fromImage("/animations/walking/wwalk1.PNG");
		walkingLeftSprites[1]=Sprite.fromImage("/animations/walking/wwalk2.PNG");
		walkingLeftSprites[2]=Sprite.fromImage("/animations/walking/wwalk3.PNG");
		walkingLeftSprites[3]=Sprite.fromImage("/animations/walking/wwalk4.PNG");
		walkingLeftSprites[4]=Sprite.fromImage("/animations/walking/wwalk5.PNG");
		walkingLeftSprites[5]=Sprite.fromImage("/animations/walking/wwalk6.PNG");
		walkingLeftSprites[6]=Sprite.fromImage("/animations/walking/wwalk7.PNG");
		walkingLeftSprites[7]=Sprite.fromImage("/animations/walking/wwalk8.PNG");
		walkingLeftSprites[8]=Sprite.fromImage("/animations/walking/wwalk9.PNG");
		walkingLeftSprites[9]=Sprite.fromImage("/animations/walking/wwalk10.PNG");
		walkingLeftSprites[10]=Sprite.fromImage("/animations/walking/wwalk11.PNG");
		walkingLeftSprites[11]=Sprite.fromImage("/animations/walking/wwalk12.PNG");
		walkingLeftSprites[12]=Sprite.fromImage("/animations/walking/wwalk13.PNG");
		walkingLeftSprites[13]=Sprite.fromImage("/animations/walking/wwalk14.PNG");
		walkingLeftSprites[14]=Sprite.fromImage("/animations/walking/wwalk15.PNG");
		
		animations.put("walkLeft", walkingLeftSprites);
		
		Sprite[] walkingRightSprites = new Sprite[15];
		
		walkingRightSprites[0]=Sprite.fromImage("/animations/walking/wwalk1r.PNG");
		walkingRightSprites[1]=Sprite.fromImage("/animations/walking/wwalk2r.PNG");
		walkingRightSprites[2]=Sprite.fromImage("/animations/walking/wwalk3r.PNG");
		walkingRightSprites[3]=Sprite.fromImage("/animations/walking/wwalk4r.PNG");
		walkingRightSprites[4]=Sprite.fromImage("/animations/walking/wwalk5r.PNG");
		walkingRightSprites[5]=Sprite.fromImage("/animations/walking/wwalk6r.PNG");
		walkingRightSprites[6]=Sprite.fromImage("/animations/walking/wwalk7r.PNG");
		walkingRightSprites[7]=Sprite.fromImage("/animations/walking/wwalk8r.PNG");
		walkingRightSprites[8]=Sprite.fromImage("/animations/walking/wwalk9r.PNG");
		walkingRightSprites[9]=Sprite.fromImage("/animations/walking/wwalk10r.PNG");
		walkingRightSprites[10]=Sprite.fromImage("/animations/walking/wwalk11r.PNG");
		walkingRightSprites[11]=Sprite.fromImage("/animations/walking/wwalk12r.PNG");
		walkingRightSprites[12]=Sprite.fromImage("/animations/walking/wwalk13r.PNG");
		walkingRightSprites[13]=Sprite.fromImage("/animations/walking/wwalk14r.PNG");
		walkingRightSprites[14]=Sprite.fromImage("/animations/walking/wwalk15r.PNG");
		
		animations.put("walkRight", walkingRightSprites);
				
	}
	
	private void addAnimationWormFalling(){
		Sprite[] fallSprites = new Sprite[2];
		fallSprites[0]=Sprite.fromImage("/images/worm/wfall1.PNG");
		fallSprites[1]=Sprite.fromImage("/images/worm/wfall2.PNG");
		
		animations.put("falling", fallSprites);
		

	}
	
	private void addAnimationWormJumping(){
		Sprite[] jumpLeftSprites = new Sprite[7];
		Sprite[] jumpRightSprites = new Sprite[7];
		jumpLeftSprites[0]=Sprite.fromImage("/animations/jumping/wjump1.PNG");
		jumpLeftSprites[1]=Sprite.fromImage("/animations/jumping/wjump2.PNG");
		jumpLeftSprites[2]=Sprite.fromImage("/animations/jumping/wjump3.PNG");
		jumpLeftSprites[3]=Sprite.fromImage("/animations/jumping/wjump4.PNG");
		jumpLeftSprites[4]=Sprite.fromImage("/animations/jumping/wjump5.PNG");
		jumpLeftSprites[5]=Sprite.fromImage("/animations/jumping/wjump6.PNG");
		jumpLeftSprites[6]=Sprite.fromImage("/animations/jumping/wjump7.PNG");
		
		jumpRightSprites[0]=Sprite.fromImage("/animations/jumping/wjump1r.PNG");
		jumpRightSprites[1]=Sprite.fromImage("/animations/jumping/wjump2r.PNG");
		jumpRightSprites[2]=Sprite.fromImage("/animations/jumping/wjump3r.PNG");
		jumpRightSprites[3]=Sprite.fromImage("/animations/jumping/wjump4r.PNG");
		jumpRightSprites[4]=Sprite.fromImage("/animations/jumping/wjump5r.PNG");
		jumpRightSprites[5]=Sprite.fromImage("/animations/jumping/wjump6r.PNG");
		jumpRightSprites[6]=Sprite.fromImage("/animations/jumping/wjump7r.PNG");
		
		animations.put("jumpingLeft", jumpLeftSprites);
		animations.put("jumpingRight", jumpRightSprites);

	}
	
	public void addAnimationBazooka(){
		Sprite[] bazLeftSprites = new Sprite[7];
		Sprite[] bazRightSprites = new Sprite[7];
		bazLeftSprites[0]=Sprite.fromImage("/animations/weapons/wbaz1.PNG");
		bazLeftSprites[1]=Sprite.fromImage("/animations/weapons/wbaz2.PNG");
		bazLeftSprites[2]=Sprite.fromImage("/animations/weapons/wbaz3.PNG");
		bazLeftSprites[3]=Sprite.fromImage("/animations/weapons/wbaz4.PNG");
		bazLeftSprites[4]=Sprite.fromImage("/animations/weapons/wbaz5.PNG");
		bazLeftSprites[5]=Sprite.fromImage("/animations/weapons/wbaz6.PNG");
		bazLeftSprites[6]=Sprite.fromImage("/animations/weapons/wbaz7.PNG");
		
		bazRightSprites[0]=Sprite.fromImage("/animations/weapons/wbaz1r.PNG");
		bazRightSprites[1]=Sprite.fromImage("/animations/weapons/wbaz2r.PNG");
		bazRightSprites[2]=Sprite.fromImage("/animations/weapons/wbaz3r.PNG");
		bazRightSprites[3]=Sprite.fromImage("/animations/weapons/wbaz4r.PNG");
		bazRightSprites[4]=Sprite.fromImage("/animations/weapons/wbaz5r.PNG");
		bazRightSprites[5]=Sprite.fromImage("/animations/weapons/wbaz6r.PNG");
		bazRightSprites[6]=Sprite.fromImage("/animations/weapons/wbaz7r.PNG");
	
		animations.put("bazookaLeft", bazLeftSprites);
		animations.put("bazookaRight", bazRightSprites);
	}
	
	public void addAnimationGun(){
		Sprite[] gunLeftSprites = new Sprite[7];
		Sprite[] gunRightSprites = new Sprite[7];
		gunLeftSprites[0]=Sprite.fromImage("/animations/weapons/gun/gun1.PNG");
		gunLeftSprites[1]=Sprite.fromImage("/animations/weapons/gun/gun2.PNG");
		gunLeftSprites[2]=Sprite.fromImage("/animations/weapons/gun/gun3.PNG");
		gunLeftSprites[3]=Sprite.fromImage("/animations/weapons/gun/gun4.PNG");
		gunLeftSprites[4]=Sprite.fromImage("/animations/weapons/gun/gun5.PNG");
		gunLeftSprites[5]=Sprite.fromImage("/animations/weapons/gun/gun6.PNG");
		gunLeftSprites[6]=Sprite.fromImage("/animations/weapons/gun/gun7.PNG");
		
		gunRightSprites[0]=Sprite.fromImage("/animations/weapons/gun/gun1r.PNG");
		gunRightSprites[1]=Sprite.fromImage("/animations/weapons/gun/gun2r.PNG");
		gunRightSprites[2]=Sprite.fromImage("/animations/weapons/gun/gun3r.PNG");
		gunRightSprites[3]=Sprite.fromImage("/animations/weapons/gun/gun4r.PNG");
		gunRightSprites[4]=Sprite.fromImage("/animations/weapons/gun/gun5r.PNG");
		gunRightSprites[5]=Sprite.fromImage("/animations/weapons/gun/gun6r.PNG");
		gunRightSprites[6]=Sprite.fromImage("/animations/weapons/gun/gun7r.PNG");
	
		animations.put("gunLeft", gunLeftSprites);
		animations.put("gunRight", gunRightSprites);
	}
	
	public void addAnimationDinamite(){
		Sprite[] dinamiteLeftSprites = new Sprite[7];
		Sprite[] dinamiteRightSprites = new Sprite[7];
		dinamiteLeftSprites[0]=Sprite.fromImage("/animations/weapons/dinamite/dinamite1.PNG");
		dinamiteLeftSprites[1]=Sprite.fromImage("/animations/weapons/dinamite/dinamite2.PNG");
		dinamiteLeftSprites[2]=Sprite.fromImage("/animations/weapons/dinamite/dinamite3.PNG");
		dinamiteLeftSprites[3]=Sprite.fromImage("/animations/weapons/dinamite/dinamite4.PNG");
		dinamiteLeftSprites[4]=Sprite.fromImage("/animations/weapons/dinamite/dinamite5.PNG");
		dinamiteLeftSprites[5]=Sprite.fromImage("/animations/weapons/dinamite/dinamite6.PNG");
		dinamiteLeftSprites[6]=Sprite.fromImage("/animations/weapons/dinamite/dinamite7.PNG");
		
		dinamiteRightSprites[0]=Sprite.fromImage("/animations/weapons/dinamite/dinamite1r.PNG");
		dinamiteRightSprites[1]=Sprite.fromImage("/animations/weapons/dinamite/dinamite2r.PNG");
		dinamiteRightSprites[2]=Sprite.fromImage("/animations/weapons/dinamite/dinamite3r.PNG");
		dinamiteRightSprites[3]=Sprite.fromImage("/animations/weapons/dinamite/dinamite4r.PNG");
		dinamiteRightSprites[4]=Sprite.fromImage("/animations/weapons/dinamite/dinamite5r.PNG");
		dinamiteRightSprites[5]=Sprite.fromImage("/animations/weapons/dinamite/dinamite6r.PNG");
		dinamiteRightSprites[6]=Sprite.fromImage("/animations/weapons/dinamite/dinamite7r.PNG");
	
		animations.put("dinamiteLeft", dinamiteLeftSprites);
		animations.put("dinamiteRight", dinamiteRightSprites);
	}
	
	public static Animation getExplosion(){
		Animation anim;
		anim = new Animation(0.08, animations.get("explosion"));
		return anim;
	}
	public static Animation getAnimation(String name, double time){
		Animation anim;
		Sprite[] sp =animations.get(name); 
		if (sp == null){
			throw new RuntimeException("Sprites of " + name + " was not found");
		}
		anim = new Animation(time, sp);
		return anim;	
	}
	
	public static Animation getLinealAnimation(String name, double time){
		LinealAnimation anim;
		Sprite[] sp =animations.get(name); 
		if (sp == null){
			throw new RuntimeException("Sprites of " + name + " was not found");
		}
		anim = new LinealAnimation(time, sp);
		return anim;	
	}
	
}
